﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.Entity;
using COM.OA.BLL;
using System.Web.Caching;
using System.Collections.Generic;

public partial class index_top_messagetimer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void 接收消息定时器_Tick1(object sender, EventArgs e)
    {
        IList<message> newslist = null;


        //判断缓存是否为空~
        if (this.Cache["messagelist"] == null)
        {
            //如果为空查询一次数据
            newslist = messageBLL.Select();
            //实例缓存依赖
            AggregateCacheDependency dependency = new AggregateCacheDependency();
            //绑定要轮询的数据库和表
            dependency.Add(new SqlCacheDependency("OA_DB", "message"));
            //将数据添加进缓存
            this.Cache.Insert("messagelist", newslist, dependency, DateTime.Now.AddHours(1), TimeSpan.Zero);
            //从session里取登陆人信息
            users loginuser = Session["loginuser"] as users;
            //设置where语句
            String where = "m_u_id='{0}' and m_isreturn='{1}'";
            int uid = loginuser.u_id;
            int isreturn = 0;
            where = string.Format(where, uid, isreturn);
            //按条件查询，并返回表关系
            IList<message> newlist = messageBLL.Select(where,true,false);
            //判断返回是否有值（数据库绑定表是否有新消息）
            if (newlist.Count != 0)
            {
                //将数据放进session，存起来
                Session.Add("newlist", newlist);
                //弹出新窗口提示，并显示相关信息。
                //this.Response.Write(string.Format(GetRedirect.WINALERT,"您有新的消息,请注意查收!"));
                this.Response.Write("<script>window.open('tanchuxiaoxi.aspx','','height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');</script>");
            }
        }
            //如果数据库无变动，读取缓存信息作为数据源。
        else
        {
            if (this.Cache["messagelist"] is IList<message>)
            {
                newslist = this.Cache["messagelist"] as IList<message>;
            }
        }

    }
}
